
var a=[1,2,3];
var b=[4,5,6,7];


var c=fn(a,b);
c.forEach(function(item,index,arr){

  console.log(item);

});


function fn(arr1,arr2){
  var arr=[];
  var l1=arr1.length;
  var l2=arr2.length;
  var l;
  l=Math.max(l1,l2);
  if(l!=0){
    for(var i=0;i<l;i++)
    {
      if(((i+1)<=l1)&&((i+1)<=l2))
      {
        arr.push(arr1[i]);
        arr.push(arr2[i]);
      }
      else {
        if((i+1)>l1){
          arr.push(arr2[i]);
        }
        if((i+1)>l2){
          arr.push(arr1[i]);
        }
      }

    }
  }

  return arr;
}
